-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug due to pandas
release
#359
Conversation
Codecov Report
@@ Coverage Diff @@
## master #359 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 953 954 +1
=========================================
+ Hits 953 954 +1
Continue to review full report at Codecov.
|
@@ -156,7 +156,7 @@ def test__get_intervals_nans(self): | |||
categorical value (start, end). | |||
""" | |||
# Setup | |||
data = pd.Series(['foo', np.nan, None, 'foo', 'foo', 'tar']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the expected value instead of this part? I think it's good to know how this function handles None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't really do it, since there are two distinct behaviors for this input, depending on what version of pandas we are running. For pandas 1.4.0
, the existing code doesn't even work on this input. Notice that the categorical transformer does the following:
RDT/rdt/transformers/categorical.py
Lines 106 to 109 in 40d2667
if pd.isna(value): | |
value = np.nan | |
intervals[value] = (start, end, mean, std) |
So we actually just overwrite the first np.nan
with the None
, which is not the intended behavior. If we do want to keep support for multiple types of nan's, we could cast all null objects no np.nan
right at the start of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird that value__counts
doesn't treat None
as np.nan
, but pd.isna
will still return True
for it. My question is, is it possible for _get_intervals
to receive data with different null types. If so, we have to handle that which means I think we should convert them all before doing the value_counts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe we can remove some lines but besides that LGTM!
@@ -89,6 +89,7 @@ def _get_intervals(data): | |||
dict: | |||
intervals for each categorical value (start, end). | |||
""" | |||
data = data.fillna(np.nan) | |||
frequencies = data.value_counts(dropna=False) | |||
|
|||
start = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these lines still necessary?
https://github.com/sdv-dev/RDT/pull/359/files#diff-a773101f2762f769e16ea74de27ab3ebe5db4fba702dfe4197dedd5060517842L106-L107
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Check #360.
Resolves #358 by converting all null-like values to
np.nan
in the_get_intervals
method.